<?php

/**
 * Plugin que Manipula a view antes de mandar para o browser
 *
 */

class Core_View_Plugin extends Zend_Controller_Plugin_Abstract{
	public function preDispatch(Zend_Controller_Request_Abstract $request){
		$this->_setLayout();
		Zend_Layout::getMvcInstance()->getView()->baseHostUrl = "http://" . $_SERVER['HTTP_HOST'];
		Zend_Layout::getMvcInstance()->getView()->baseUrl = !Zend_Controller_Front::getInstance()->getBaseUrl() ? "http://" . $_SERVER['HTTP_HOST'] : Zend_Controller_Front::getInstance()->getBaseUrl();
		Zend_Layout::getMvcInstance()->getView()->baseUrlController = Zend_Controller_Front::getInstance()->getBaseUrl() . '/' . $request->getControllerName();
		Zend_Layout::getMvcInstance()->getView()->controllerName = $request->getControllerName();
		Zend_Layout::getMvcInstance()->getView()->action = $request->getControllerName() . '/' . $request->getActionName();
		Zend_Layout::getMvcInstance()->getView()->media = Zend_Layout::getMvcInstance()->getView()->baseUrl . "/media/";
		Zend_Layout::getMvcInstance()->getView()->admin = Zend_Layout::getMvcInstance()->getView()->media . "admin/";
		Zend_Layout::getMvcInstance()->getView()->css = Zend_Layout::getMvcInstance()->getView()->media . "css/";
		Zend_Layout::getMvcInstance()->getView()->flash = Zend_Layout::getMvcInstance()->getView()->media . "flash/";
		Zend_Layout::getMvcInstance()->getView()->fonts = Zend_Layout::getMvcInstance()->getView()->media . "fonts/";
    Zend_Layout::getMvcInstance()->getView()->imagens = Zend_Layout::getMvcInstance()->getView()->media . "imagens/";
    Zend_Layout::getMvcInstance()->getView()->js = Zend_Layout::getMvcInstance()->getView()->media . "js/";
    Zend_Layout::getMvcInstance()->getView()->scripts = Zend_Layout::getMvcInstance()->getView()->media . "scripts/";
    Zend_Layout::getMvcInstance()->getView()->xml = Zend_Layout::getMvcInstance()->getView()->media . "xml/";
	}

	public function _setLayout(){
	  if(Zend_Layout::getMvcInstance()->getView()->controllerName == 'admin')
	    Zend_Layout::getMvcInstance()->setLayout('administration');	
	  elseif(Zend_Layout::getMvcInstance()->getView()->controllerName == 'account')
      Zend_Layout::getMvcInstance()->setLayout('login');	    
	  else{
	    Zend_Layout::getMvcInstance()->setLayout('layout');
	  }
		
	}
}

?>